<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        #app {
            border: 2px solid black;
            padding: 10px;
            margin-bottom: 400px;
        }

        .child {
            margin: 20px;
            padding: 10px;
            background-color: #cccccc;
        }
    </style>
</head>

<body>
    <div id="app">
        <h3>父组件</h3>
        <input type="button" value="切换组件One" @click=" name='ChildOne' ">
        <input type="button" value="切换组件Two" @click=" name='ChildTwo' ">
        <!-- <child-one></child-one>
        <child-two></child-two> -->
        <!-- <keep-alive include="ChildOne"> -->
        <!-- <keep-alive :include="/Two$/"> -->
        <!-- <keep-alive exclude="ChildOne,ChildTwo"> -->
            <component :is=" name " class="a" :msg="msg"></component>
        </keep-alive>
    </div>
    <template id="ChildOne">
        <div class="child" id="组件One">
            <h3>子组件one</h3>
        </div>
    </template>
    <template id="ChildTwo">
        <div class="child" id="组件Two">
            <h3>子组件two</h3>
        </div>
    </template>
</body>
<script>
    Vue.component("ChildOne", {
        template: "#ChildOne",
        beforeCreate() {
            console.log("ChildOne:beforeCreate")
        },
        beforeDestroy() {
            console.log("ChildOne:beforeDestroy")
        },
        activated() {
            console.log("ChildOne:显示");
        },
        deactivated(){
            console.log("ChildOne:隐藏")
        }
    });
    Vue.component("ChildTwo", {
        template: "#ChildTwo",
        beforeCreate() {
            console.log("ChildTwo:beforeCreate")
        },
        beforeDestroy() {
            console.log("ChildTwo:beforeDestroy")
        },
        activated() {
            console.log("ChildTwo:显示");
        },
        deactivated(){
            console.log("ChildTwo:隐藏")
        }
    });

    // 动态组件实在 固定的vue实例的容器中，进行动态化的组件切换
    new Vue({
        el: "#app",
        data:{
            name:"ChildOne",
            msg:"测试数据"
        },
    });

</script>

</html>